
module.exports = {
  pingKongIfKdjTrans () {
    if (this.ifOnlyPingKongByReason) {
      return
    }
    if (this.analysisInfo15m.kdjDiff > 0 && this.strategy === '1') {
      if (
        this.analysisInfo15m.lastKdjDownRate <= -20 &&
        (!this.isLongMarketBadAnd15mDown() || this.analysisInfo15m.lastKdjDownRate <= -40) &&
        !this.marketFlagInfo.isMarketLittleBadDown
      ) {
        this.setPingKong('pingKongIfKdjTrans-2')
      }
      if (
        this.analysisInfo15m.lastKdjDownDays >= 13 &&
        (!this.isLongMarketBadAnd15mDown() || this.analysisInfo15m.lastKdjDownRate <= -40) &&
        !this.marketFlagInfo.isMarketLittleBadDown
      ) {
        this.setPingKong('pingKongIfKdjTrans-3')
      }
    }
  },
  pingKongIfMarketInfo () {
    if (this.ifOnlyPingKongByReason) {
      return
    }
    if (!this.marketInfo) {
      return
    }
    if (this.marketInfo) {
      if (this.marketFlagInfo.ifMarketNoDirection) {
        // 没有方向的状态
        if (this.hasKongPosition && (this.strategy === '2' || this.btbItem.strategy === '2')) {
          if (
            this.analysisInfo15m.ema5 < this.analysisInfo15m.ema10 ||
            this.analysisInfo15m.macd < 0 ||
            this.analysisInfo15m.close < this.analysisInfo15m.ema10 ||
            this.analysisInfo15m.netChangeRatioDownDays >= 3 ||
            this.analysisInfo15m.close < this.analysisInfo15m.ema20
          ) {
            this.setPingKong('pingKongIfMarketInfo-1-1')
          }
        }
      }
      if (this.strategy === '2' && this.hasKongPosition && !this.marketFlagInfo.ifMarket15mAllGood) {
        if (this.marketInfo.kdj4hGood && (this.marketInfo.kdj1hGood || this.marketInfo.macd1hGood)) {
          if (
            this.analysisInfo15m.ema5 < this.analysisInfo15m.ema10 &&
            (
              this.analysisInfo15m.close < this.analysisInfo15m.ema5 &&
              this.analysisInfo15m.close < this.analysisInfo15m.ema10 &&
              this.analysisInfo15m.close < this.analysisInfo15m.ema20
            )
          ) {
            this.setPingKong('pingKongIfMarketInfo-2')
          }
        }
        if (
          !this.marketFlagInfo.indexIfMarketDownTrend ||
          this.btbItem.keep_days >= 12
        ) {
          if (
            this.analysisInfo15m.ema5 > this.analysisInfo15m.ema10 &&
            this.analysisInfo15m.ema10 > this.analysisInfo15m.ema20 &&
            (
              this.analysisInfo15m.close < this.analysisInfo15m.ema5 &&
              this.analysisInfo15m.close < this.analysisInfo15m.ema10 &&
              this.analysisInfo15m.close < this.analysisInfo15m.ema20
            )
          ) {
            this.setPingKong('pingKongIfMarketInfo-3', {
              rate: 0.5
            })
          }
          if (
            this.analysisInfo15m.ema5 < this.analysisInfo15m.ema20 &&
            (
              this.analysisInfo15m.close < this.analysisInfo15m.ema5 &&
              this.analysisInfo15m.close < this.analysisInfo15m.ema10 &&
              this.analysisInfo15m.close < this.analysisInfo15m.ema20
            )
          ) {
            this.setPingKong('pingKongIfMarketInfo-4')
          }
          if (
            this.analysisInfo15m.netChangeRatioDownDays >= 3 &&
            this.analysisInfo15m.close < this.analysisInfo15m.ema10
          ) {
            let pRate = (
              (this.analysisInfo15m.close < this.analysisInfo15m.ema20) ||
              (this.analysisInfo15m.ema5 < this.analysisInfo15m.ema10) ||
              (this.marketInfo.kdj15mBad && !this.marketInfo.macd15mGood)
            ) ? 1 : 0.5
            if (this.symbolAccount.incomeRate >= 0.8) {
              this.setPingKong('pingKongIfMarketInfo-5', {
                rate: 1 * pRate
              })
            } else {
              this.setPingKong('pingKongIfMarketInfo-5-1', {
                rate: 0.5 * pRate
              })
            }
          }
        }
        if (
          (this.marketInfo.macd4hGood && this.marketInfo.ema4hGood && this.marketInfo.kdj4hGood) &&
          !(this.marketInfo.macd1hBad || this.marketInfo.ema1hBad)
        ) {
          if (
            this.analysisInfo15m.netChangeRatioDownDays >= 3 &&
            this.analysisInfo15m.close < this.analysisInfo15m.ema20
          ) {
            this.setPingKong('pingKongIfMarketInfo-5-2')
          }
        }
      }
    }
    if (this.hasKongPosition && this.symbolAccount.position > 0.6) {
      if (this.symbolAccount.incomeRate >= 0.4 && this.strategy === '1') {
        if (
          this.marketInfo.kdj15mGood &&
          !(this.marketInfo.macd15mGood || this.marketInfo.ema15mGood) &&
          !this.isLongMarketBadAnd15mDown() &&
          !this.marketFlagInfo.isMarketBigBadDown
        ) {
          this.setPingKong('pingKongIfMarketInfo-6', {
            rate: 0.5
          })
        }
      }
    }
    let preCutRate = this.indexFlagInfo.isIndexInNewLowTrend ? 0.25 : 0.3
    if (this.marketFlagInfo.isMarketBigBadDown) {
      preCutRate = 0.15
    }
    if (this.hasKongPosition && this.symbolAccount.position > 0.2) {
      if (this.symbolAccount.incomeRate >= 0.4) {
        if (this.marketFlagInfo.ifMarket15mAllBad) {
          if (this.marketFlagInfo.isMarketFakeBadDown) {
            preCutRate = 0.50
          }
          this.setPingKong('pingKongIfMarketInfo-7', {
            rate: preCutRate
          })
        }
      }
    }
    if (
      (this.marketInfo.kdj15mBad && !this.marketInfo.macd15mBad && !this.marketInfo.ema15mBad) &&
      (!this.marketInfo.kdj1hBad && !this.marketInfo.macd1hBad && this.marketInfo.ema1hBad) &&
      !this.marketFlagInfo.isMarketBigBadDown
    ) {
      this.setPingKong('pingKongIfMarketInfo-7-1', {
        rate: this.indexFlagInfo.isIndexInNewLowTrend ? 0.15 : 0.2
      })
      if (this.analysisInfo15m.macdDownDays >= 1 && this.analysisInfo15m.macdDownDays <= 2) {
        this.setPingKong('pingKongIfMarketInfo-7-1', {
          rate: this.indexFlagInfo.isIndexInNewLowTrend ? 0.4 : 0.5
        })
      }
    }
    if (
      (this.marketInfo.kdj4hGood && !this.marketInfo.macd4hBad) &&
      (this.marketInfo.macd1hGood)
    ) {
      if (this.hasKongPosition && this.strategy === '2') {
        if ((this.marketInfo.kdj15mBad && !this.marketInfo.macd15mGood)) {
          // 还行
          this.setPingKong('pingKongIfMarketInfo-8-1', {
            rate: 0.5
          })
        }
      }
    }
    if (this.marketFlagInfo.ifMarket15mAllBad) {
      if (this.hasKongPosition && this.symbolAccount.incomeRate < -1 && this.btbItem.keep_days > 2) {
        this.setPingKong('pingKongIfMarketInfo-9-1', {
          rate: 0.5
        })
      }
    }
    if (
      (this.marketFlagInfo.ifMarket1dMacdEmaAllGood && this.marketFlagInfo.ifMarket4hMacdEmaAllGood) &&
      (this.marketInfo.ema1hGood && this.marketInfo.kdj1hGood) &&
      (this.marketInfo.ema15mGood && !this.marketInfo.macd1hGood && !this.marketFlagInfo.ifMarket15mHasBad)
    ) {
      if (this.hasKongPosition && this.strategy === '2') {
        this.setPingKong('pingKongIfMarketInfo-10-1', {
          rate: 0.5
        })
      }
    }
    if (
      (this.marketInfo.ema15mBad && this.marketInfo.macd15mBad) &&
      (this.hasKongPosition && this.btbItem.strategy === '2') &&
      this.btbItem.keep_days >= 4
    ) {
      this.setPingKong('pingKongIfMarketInfo-10-2', {
        rate: 0.5
      })
    }
    if (this.hasKongPosition && this.btbItem.strategy === '2' && this.btbItem.keep_days >= 8) {
      if (this.marketInfo.kdj4hGood && this.marketInfo.kdj1hGood && this.marketInfo.ema1hGood) {
        if (
          this.analysisInfo15m.macdUpDays >= 1 &&
          (this.analysisInfo15m.macdUpDays + this.analysisInfo15m.lastMacdDownDays) < this.btbItem.keep_days &&
          this.analysisInfo15m.isDuo
        ) {
          // 挺好的，即使是在all的时候平仓了
          this.setPingKong('pingKongIfMarketInfo-10-3', {
            rate: this.analysisInfo15m.macdUpDays >= 2 ? 1 : 0.5
          })
        }
      }
    }
    if (
      (this.marketInfo.ema15mBad && this.marketInfo.macd15mBad) ||
      (this.marketInfo.kdj15mBad && this.marketInfo.macd15mBad && !this.marketInfo.ema15mGood)
      // 环境不好你还逆向新高
    ) {
      if (
        (this.hasKongPosition && this.btbItem.strategy === '2') &&
        this.symbolAccount.incomeRate < 0 &&
        // 是新高
        this.indexFlagInfo.isIndexCloseNewHigh &&
        this.analysisInfo15m.isLongDuo &&
        this.analysisInfo1h.isLongDuo
      ) {
        this.setPingKong('pingKongIfMarketInfo-10-4')
      }
    }
  },
  pingKongIfMacdDownManyDaysUp () {
    if (this.ifOnlyPingKongByReason) {
      return
    }
    if (
      this.analysisInfo15m.macd > 0 &&
      (
        this.analysisInfo15m.ema5 > this.analysisInfo15m.ema20 ||
        this.analysisInfo15m.ema10 > this.analysisInfo15m.ema20
      )
    ) {
      if (this.strategy === '2' && this.symbolAccount.incomeRate >= 1) {
        // 逆向
        if (this.analysisInfo15m.ema5A10A20Days >= 1) {
          this.setPingKong('pingKongIfMacdDownManyDaysUp-10-1', {
            canReverse: true
          })
        }
      } else {
        this.setPingKong('pingKongIfMacdDownManyDaysUp-10', {
          canReverse: true
        })
      }
    }
    if (
      this.analysisInfo15m.lastMacdDownDays >= 20 &&
      (
        this.analysisInfo15m.ema5W10B20Days >= 20 ||
        this.analysisInfo15m.lastEma5W10B20Days >= 20
      )
    ) {
      if (
        this.analysisInfo15m.macdUpDays >= 4 &&
        this.analysisInfo15m.kdjUpDays >= 6
      ) {
        if (this.strategy === '2') {
          if (!(this.marketInfo.macd1hGood && this.marketInfo.ema1hGood && this.marketInfo.macd4hGood && this.marketInfo.ema4hGood)) {
            // 逆向
            if (this.analysisInfo15m.ema5A10A20Days >= 1) {
              this.setPingKong('pingKongIfMacdDownManyDaysUp-1-2', {
                canReverse: true
              })
            }
          }
        } else {
          this.setPingKong('pingKongIfMacdDownManyDaysUp-1', {
            canReverse: true
          })
        }
      }
      if (
        this.analysisInfo15m.macdUpDays >= 6 &&
        this.analysisInfo15m.kdjDiff > 0
      ) {
        if (this.strategy === '2' && this.symbolAccount.incomeRate >= 1) {
          // 逆向
          if (this.analysisInfo15m.ema5A10A20Days >= 1) {
            this.setPingKong('pingKongIfMacdDownManyDaysUp-1-3', {
              canReverse: true
            })
          }
        } else {
          this.setPingKong('pingKongIfMacdDownManyDaysUp-1-1', {
            canReverse: true
          })
        }
      }
    }
    if (
      this.analysisInfo1h.lastMacdDownDays >= 20 &&
      (
        this.analysisInfo1h.ema5W10B20Days >= 20 ||
        this.analysisInfo1h.lastEma5W10B20Days >= 20
      )
    ) {
      if (
        this.analysisInfo1h.macdUpDays >= 4 &&
        this.analysisInfo1h.kdjUpDays >= 6
      ) {
        this.setPingKong('pingKongIfMacdDownManyDaysUp-2', {
          canReverse: true
        })
      }
      if (
        this.analysisInfo1h.macdUpDays >= 6 &&
        this.analysisInfo1h.kdjDiff > 0
      ) {
        this.setPingKong('pingKongIfMacdDownManyDaysUp-2-2', {
          canReverse: true
        })
      }
    }
  },
  pingKongIfNowDownHigh () {
    // 正负数要搞灵清
    // if (this.analysisInfo15m.netChangeRatio < -12) {
    //   this.setNoSell()
    //   this.setPingKong('pingKongIfNowDownHigh-1')
    // }
    if (
      this.analysisInfo15m.macdDownRate < -50 &&
      this.analysisInfo15m.macd < 0 &&
      this.analysisInfo15m.kdjDiff > 0
    ) {
      this.setNoSell()
      this.setPingKong('pingKongIfNowDownHigh-1')
    }
  },
  pingKongReversePosition () {
    if (this.ifOnlyPingKongByReason) {
      return
    }
    if (this.strategy === '1' && this.btbItem.strategy === '2' && this.marketFlagInfo.isMarketLittleGoodUp) {
      if (this.hasKongPosition && this.symbolAccount.incomeRate <= -2) {
        this.setPingKong('pingKongReversePosition-1')
        this.manual = 1
      }
    }
  },
  pingKongIfProfitReduce () {
    if (this.ifOnlyPingKongByReason) {
      return
    }
    if (this.sell) {
      return
    }
    const max_income_rate = this.btbItem.max_income_rate || 0
    if (this.hasKongPosition && max_income_rate >= 6) {
      if (this.symbolAccount.incomeRate < max_income_rate * 0.66666) {
        // this.setPingKong('pingKongIfProfitReduce-1')
      }
    }
  },
  pingKongIfStopLoss () {
    let baseLossRate = -12
    if (this.hasKongPosition) {
      if (this.btbItem.strategy === '2') {
        if (
          this.symbolAccount.incomeRate <= baseLossRate &&
          !this.marketFlagInfo.ifMarket15mAllGood &&
          this.analysisInfo15m.netChangeRatio < 5
        ) {
          this.setPingKong('pingKongIfStopLoss-1')
          this.manual = 1
        }
        // if (this.symbolAccount.incomeRate <= -2 && this.btbItem.keep_days > 6) {
        //   this.setPingKong('pingKongIfStopLoss-2')
        // }
        if (this.symbolAccount.incomeRate < 0 && this.btbItem.keep_days > 25) {
          if (
            this.analysisInfo15m.ema5 < this.analysisInfo15m.ema10 ||
            this.analysisInfo15m.macd < 0 ||
            this.analysisInfo15m.close < this.analysisInfo15m.ema10 ||
            this.analysisInfo15m.netChangeRatioDownDays >= 3 ||
            this.analysisInfo15m.close < this.analysisInfo15m.ema20
          ) {
            this.setPingKong('pingKongIfStopLoss-2-1')
          }
        }
        if (this.btbItem.keep_days >= 17 && (this.symbolAccount.incomeRate < 0 || !this.sell)) {
          if (this.analysisInfo15m.ema5 < this.analysisInfo15m.ema10) {
            this.setPingKong('pingKongIfStopLoss-2-2')
          }
          if (
            this.analysisInfo15m.macd < 0 &&
            this.analysisInfo15m.close < this.analysisInfo15m.ema10 &&
            this.analysisInfo15m.netChangeRatioDownDays >= 3
          ) {
            this.setPingKong('pingKongIfStopLoss-2-3')
          }
          if (this.analysisInfo15m.close < this.analysisInfo15m.ema20) {
            this.setPingKong('pingKongIfStopLoss-2-4')
          }
        }
        if (this.symbolAccount.incomeRate < 0 && this.btbItem.keep_days > 32) {
          this.setPingKong('pingKongIfStopLoss-2-5')
        }
        if (
          this.symbolAccount.incomeRate <= -2 &&
          // 说明有可能看错了
          (this.marketInfo && (this.marketInfo.attack15mKdjGood)) &&
          this.analysisInfo15m.kdjDiff > 0
        ) {
          // 错了马上止损确实能保命
          // this.setPingKong('pingKongIfStopLoss-2-2')
        }
        // 新高的，逆向仓位，亏损超过1的本金，就开始不断减仓
        if (this.symbolAccount.incomeAssetRate <= -1.5 && this.symbolAccount.incomeRate <= -8 && this.hasKongPosition) {
          if (this.indexFlagInfo.isIndexCloseNowNewHigh && this.marketInfo.newHighRate < 0.1) {
            // 同时新高的东西并不多
            this.setPingKong('pingKongIfStopLoss-2-6', {
              rate: 0.2
            })
          }
        }
        // 逆向做空的，如果加过仓，然后变亏损了，然后这个k又是涨的那就砍掉一半的仓位，不然就是暴涨，大金额的亏损都是这个原因
        // 是不是可以干脆做正向
        if (
          this.btbItem.add_times >= 1 &&
          this.symbolAccount.incomeRate < 0 &&
          this.btbItem.keep_days >= 5 &&
          this.analysisInfo15m.netChangeRatio > 0 &&
          this.analysisInfo15m.netChangeRatio < 7.5 &&
          this.analysisInfo15m.kdjDiff > 0 &&
          this.analysisInfo15m.isKdjIncrease
        ) {
          if (
            !(this.marketInfo.macd15mGood && this.marketInfo.ema15mGood) &&
            this.marketFlagInfo.lastMarket15mAllGoodIndex >= 6
          ) {
            this.setPingKong('pingKongIfStopLoss-2-7')
            // this.manual = 1
          }
        }
        if (this.symbolAccount.incomeAssetRate <= -1 && this.symbolAccount.incomeRate <= -6 && this.hasKongPosition) {
          if (this.btbItem.keep_days > 10 && this.analysisInfo15m.netChangeRatioDownDays >= 5) {
            this.setPingKong('pingKongIfStopLoss-2-8')
          }
        }
      } else {
        if (this.sell) {
          return
        }
        if (
          this.symbolAccount.incomeRate <= baseLossRate &&
          !this.marketFlagInfo.ifMarket15mAllGood &&
          this.analysisInfo15m.netChangeRatio < 5
        ) {
          this.setPingKong('pingKongIfStopLoss-3')
          this.manual = 1
        }
        // if (this.symbolAccount.incomeRate <= -2 && this.btbItem.keep_days > 8) {
        //   this.setPingKong('pingKongIfStopLoss-4')
        // }
        // if (this.symbolAccount.incomeRate < 0 && this.btbItem.keep_days > 17) {
        //   this.setPingKong('pingKongIfStopLoss-4-1')
        // }
        if (
          this.symbolAccount.incomeRate < 0 &&
          // 说明市场在涨
          (this.marketInfo && (this.marketInfo.crash15mKdjUp || this.marketInfo.likeKongKdjUp)) &&
          this.analysisInfo15m.kdjDiff > 0 &&
          !this.marketFlagInfo.indexIfMarketDownTrend
        ) {
          if (
            (this.analysisInfo15m.ema5 < this.analysisInfo15m.ema20 || this.analysisInfo15m.ema5A20Days <= 2) &&
            (this.marketInfo.ema1hBad && this.marketInfo.ema4hBad)
          ) {
            if (this.analysisInfo15m.netChangeRatio < 0) {
              // 错了马上止损确实能保命
              this.setPingKong('pingKongIfStopLoss-4-3')
            }
          } else {
            this.setPingKong('pingKongIfStopLoss-4-3')
          }
        }
        if (
          this.marketFlagInfo.indexIfMarket15mUpTrend &&
          !this.marketFlagInfo.indexIfMarketDownTrend &&
          this.hasKongPosition
        ) {
          // this.setPingKong('pingKongIfStopLoss-4-4')
        }
        if (
          this.marketFlagInfo.indexIfMarketDownTrend &&
          !this.marketInfo.kdj15mBad
        ) {
          if (
            (this.marketInfo.macd15mGood && !this.marketInfo.ema15mBad) ||
            (this.marketInfo.ema15mGood && !this.marketInfo.macd15mBad)
          ) {
            if (
              this.analysisInfo15m.kdjDiff > 0 &&
              !(this.marketInfo.macd1hBad && this.marketInfo.ema1hBad)
            ) {
              this.setPingKong('pingKongIfStopLoss-4-5')
            }
          }
          if (this.marketInfo.macd15mGood || this.marketInfo.ema15mGood) {
            if (this.analysisInfo15m.netChangeRatio < 0 && this.analysisInfo15m.kdjDiff < 0 && this.analysisInfo15m.macd > 0) {
              this.setPingKong('pingKongIfStopLoss-4-6')
            }
          }
        }
      }
    }
  },
  pingKongByCanOpenMany () {
    if (!this.marketInfo) {
      return
    }
    if (this.ifOnlyPingKongByReason || this.ifOnlyPingDuoByReason) {
      return
    }
    const canOpenList = this.marketInfo.canOpenList || []
    // 平衡仓位，杜绝很垃圾然后还占用很大仓位的情况
    if (this.btbItem.strategy === '2' && this.hasKongPosition && canOpenList.length > 15) {
      // canopen多说明支持的买入也多
      if (this.futuresAccount.btbCount > 25) {
        // 1.5有点多了
        if (this.symbolAccount.rawPosition >= 1.5) {
          this.setPingKong('pingKongByCanOpenMany-1-1', {
            rate: 1 - (1 / this.symbolAccount.rawPosition)
          })
        }
      }
    }
  },
  pingKongIfProfitMany () {
    if (this.ifOnlyPingKongByReason) {
      return
    }
    if (this.hasKongPosition) {
      if (this.is4hLastTime && this.symbolAccount.incomeRate >= 8) {
        this.setPingKong('pingKongIfProfitMany-1-1', {
          rate: 0.5
        })
      }
    }
  },
  pingKongForce () {
    if (this.hasKongPosition) {
      if (this.symbolAccount.incomeRate < -16 && (
        this.analysisInfo15m.macd > 0 &&
        (this.analysisInfo15m.ema5 > this.analysisInfo15m.ema20)
      )) {
        this.setPingKong('pingKongForce-1-1')
      }
    }
  }
}
